package com.example.teesystem.common.utils;

import java.util.HashMap;
/**
 * 配置统一返回数据
 *
 */
public class Response extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;
    
    /**
     * 构造方法私有
     */
    private Response() {}
    
    public Response put(String key, Object value) {
        super.put(key, value);
        return this;
    }
    
    /**
     * 成功返回
     * @return
     */
    public static Response ok() {
        return new Response().put("code", ResultCode.OK.getCode())
                .put("msg", ResultCode.OK.getMsg());
    }
    public static Response ok(Object data) {//对象
        return new Response().put("code", ResultCode.OK.getCode())
                .put("msg", ResultCode.OK.getMsg())
                .put("data", data);
    }

    /**
     * 失败返回
     * @return
     */
    public static Response error(String msg, int code) {
        return new Response().put("code", code)
                .put("msg", msg);
    }
    
    /**
     * 失败返回
     * @return
     */
    public static Response error(ResultCode resultCode) {
        return new Response().put("code", resultCode.getCode())
                .put("msg", resultCode.getMsg());
    }

    /**
     * 失败返回
     * @return
     */
    public static Response error(ResultCode resultCode, Object date) {
        return new Response().put("code", resultCode.getCode())
                .put("msg", resultCode.getMsg())
                .put("data", date);
    }
}
